import {StoreCreator} from "@/types/utils";
import {AppSliceState} from "@/store/types";
import {getDeviceLanguage} from "@/utils/modules/devices";
import languageMap from "@/theme/enums/language";
import i18next from 'i18next';

const initialState = {
    lang: languageMap[getDeviceLanguage()],
}
export const createAppSlice: StoreCreator<AppSliceState> = (set, get) => ({
    ...initialState,
    changeLanguage: (v) => {
        set(state => {
            state.lang = v;
            i18next.changeLanguage(v);
        });
    },

    reset() {
        set(initialState);
    }
})